package com.irdstudio.rsp.rule.api.rest;

import com.irdstudio.rsp.rule.service.facade.SRuleCollParamService;
import com.irdstudio.rsp.rule.service.vo.RuleParamVO;
import com.irdstudio.rsp.rule.service.vo.SRuleCollParamVO;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.beans.web.controller.AbstractController;
import com.irdstudio.sdk.ssm.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class SRuleCollParamController extends AbstractController  {
	
	@Autowired
	@Qualifier("sRuleCollParamServiceImpl")
	private SRuleCollParamService sRuleCollParamService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/params", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<SRuleCollParamVO>> querySRuleCollParamAll(
			@RequestBody SRuleCollParamVO vo) {
		List<SRuleCollParamVO> outputVo = sRuleCollParamService.queryAllOwner(vo);
		return getResponseData(outputVo);
		
	}

	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/params/dtl/get", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<RuleParamVO>> queryAllWithRuleParam(
			@RequestBody SRuleCollParamVO vo) {
		List<RuleParamVO> outputVo = sRuleCollParamService.queryAllWithRuleParam(vo);
		return getResponseData(outputVo);

	}

	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/params/dtl/update", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> updateSRuleCollParams(
			@RequestBody List<RuleParamVO> voList) {
		UserInfo userInfo = (UserInfo) this.httpRequest.getSession().getAttribute("userInfo");
		try {
			int num = sRuleCollParamService.updateSRuleCollParams(voList, userInfo);
			return getResponseData(num);
		} catch (Exception e) {
			return getResponseData(-1);
		}
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/param/{paramId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<SRuleCollParamVO> queryByPk(@PathVariable("paramId") String paramId) {		
		SRuleCollParamVO inVo = new SRuleCollParamVO();
				inVo.setParamId(new String(paramId));
		SRuleCollParamVO outputVo = sRuleCollParamService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param sRuleCollParam
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/param", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody SRuleCollParamVO inSRuleCollParamVo) {
		try {
			int outputVo = sRuleCollParamService.deleteByPk(inSRuleCollParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
	
	/**
	 * 根据主键更新信息
	 * @param inSRuleCollParamVo
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/param", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody SRuleCollParamVO inSRuleCollParamVo) {
		try {
			int outputVo = sRuleCollParamService.updateByPk(inSRuleCollParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
	
	/**
	 * 新增数据
	 * @param inSRuleCollParamVo
	 * @return
	 */
	@RequestMapping(value="/s/rule/coll/param", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertSRuleCollParam(@RequestBody SRuleCollParamVO inSRuleCollParamVo) {
		try {
			int outputVo = sRuleCollParamService.insertSRuleCollParam(inSRuleCollParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
}
